package cn.piesat.dao;

import cn.piesat.dto.PiesatMenuInfoDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Arrays;
import java.util.List;

/**
 * 菜单信息持久层
 *
 * @author xhl
 */
public interface PiesatMenuInfoDAO extends JpaRepository<PiesatMenuInfoDTO,String> {

    /**
     * 根据菜单名称查询（名称不会重复）
     * @param name 菜单名称
     * @return
     */
    PiesatMenuInfoDTO findByName(String name);

    /**
     * 根据序号排序查询所有菜单列表集合
     * @return
     */
    List<PiesatMenuInfoDTO> findAllByOrderBySeq();

    void deleteAllByIdIn(List<String> idList);

    @Query(nativeQuery = true,value = "select b.* from piesat_role_menu_relation a " +
            " left join piesat_menu_info b on a.MENU_ID = b.ID" +
            " where a.ROLE_ID in :roleId and b.LOCK_STATE = 0 order by b.SEQ")
    List<PiesatMenuInfoDTO> findLeftRoleRelation(List<String> roleId);

    List<PiesatMenuInfoDTO> findByPid(String id);

    List<PiesatMenuInfoDTO> findAllByPidIn(List<String> allList);
}
